import { reqRatingsList } from '@/api';

const state = {
  ratingsList: [],//模拟数据请求
  rating:[] // 显示到页面上的数据
};
const getters = {
  // ratings(state) {
  //   return state.ratingsList
  // },c
};
const mutations = {
  RECEIVERATINGSLIST(state, ratingsList) {
    state.ratingsList = ratingsList;
    state.rating = ratingsList;
  },
  judge(state, { evaluation , isNull }){
    if(isNull){
      // 有内容
      state.rating = state.ratingsList.filter(item=>item.text.length>0)
    }else{
      // 没有内容
      state.rating = state.ratingsList;
    }

    if(evaluation === 1){
      // 不满意
      state.rating = state.rating.filter(item=>item.rateType === 1)
    }else if(evaluation === 0){
      // 满意
      state.rating = state.rating.filter(item=>item.rateType === 0)
    }
  }
  /*
  judge(state, { evaluation , isNull }) {

    if (isNull === 1) {
      if (evaluation === 1) {
        state.ratingsList = state.ratingsList.filter(item => item.rateType === 1)
      }
      else if (evaluation === 0) {
        state.ratingsList = state.ratingsList.filter(item => item.rateType === 0)
      }
      else if (evaluation === 2) {
        state.ratingsList = state.ratingsList
      }
    }
    if (isNull === 0) {
      if (evaluation === 1) {
        state.ratingsList = state.ratingsList.filter(item => item.rateType === 1)
      }
      else if (evaluation === 0) {
        state.ratingsList = state.ratingsList.filter(item => item.rateType === 0)
      }
      else if (evaluation === 2) {
        state.ratingsList = state.ratingsList
      }
    }
    console.log(evaluation,isNull ,state.ratingsList);

  }, */

};
const actions = {
  async getRatingsList({ commit }, payload) {
    const result = await reqRatingsList();
    if (result.code === 200) {
      commit('RECEIVERATINGSLIST', result.data);
    }
  },
};

export default {
  state,
  getters,
  mutations,
  actions,
};